package com.xiao.framework.ds.example;

import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.xiao.framework.ds.autoconfigure.strategy.RandomDataSourceStrategy;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;

/**
 * @author <a href="mailto:xiaoquanidea@163.com">hutiquan</a>
 * @since 2019-08-25 9:59
 */
@MapperScan(basePackages = "com.xiao.framework.ds.example.mapper")
@SpringBootApplication
public class MultiDataSourceBootstrap {

  public static void main(String[] args) {
    new SpringApplicationBuilder()
        .sources(MultiDataSourceBootstrap.class)
        .properties("spring.profiles.active=rw")
        .web(WebApplicationType.SERVLET)
        .run(args);
  }

  @Bean
  @Profile("test")
  public PerformanceInterceptor performanceInterceptor(){
    return new PerformanceInterceptor();
  }

  @Bean
  public RandomDataSourceStrategy randomDataSourceStrategy(){
    return new RandomDataSourceStrategy();
  }
}
